package com.woniuxy.cloud52.order.web;

import com.woniuxy.cloud.UserAPI;

import com.woniuxy.cloud.ticket52.MovieAPI;
import com.woniuxy.cloud.ticket52.OrderCreateAPI;
import com.woniuxy.cloud.ticket52.common.result.Result;
import com.woniuxy.cloud.ticket52.form.OrderCreateForm;
import com.woniuxy.cloud52.SeatAPI;
import com.woniuxy.cloud52.SessionsAPI;
import com.woniuxy.cloud52.form.SeatForm;
import com.woniuxy.cloud52.order.model.Order;
import com.woniuxy.cloud52.order.service.IOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.UUID;

@RestController
@Slf4j
public class OrderCreateController implements OrderCreateAPI {
    @Autowired
    private SeatAPI seatAPI;

    @Autowired
    private MovieAPI movieAPI;

    @Autowired
    private SessionsAPI sessionsAPI;

    @Autowired
    private IOrderService service;
    /**
     * 创建订单
     * @param
     * @return
     */
    public Result create(OrderCreateForm orderCreateForm){
        log.info("创建订单：{}",orderCreateForm.getMid());
        movieAPI.getMovie(orderCreateForm.getMid());
        SeatForm seatForm = new SeatForm();
        seatForm.setMcId(orderCreateForm.getMid());
        seatForm.setNumber(orderCreateForm.getNumber());
        seatAPI.doseat(seatForm);
        sessionsAPI.getSessions(orderCreateForm.getMid());
        Order order = new Order();
        order.setCreatTime(LocalDateTime.now());
        order.setOrderNumber(UUID.randomUUID().toString());
        order.setOrderStatus("待支付");
        service.save(order);
        return Result.success();
    }



}
